|
1
|
|
|
import path from 'path'; |
|
2
|
|
|
import { delay, promisify } from 'bluebird'; |
|
3
|
|
|
import chai, { expect } from 'chai'; |
|
4
|
|
|
import fs from 'chai-fs'; |
|
5
|
|
|
import json from 'chai-json-schema'; |
|
6
|
|
|
import rimraf from 'rimraf'; |
|
7
|
|
|
import { createStream } from './helper'; |
|
8
|
|
|
|
|
9
|
|
|
chai.use(fs); |
|
10
|
|
|
chai.use(json); |
|
11
|
|
|
|
|
12
|
|
|
const rm = promisify(rimraf); |
|
13
|
|
|
|
|
14
|
|
|
const answers = [ |
|
15
|
|
|
'boilerplate-project', |
|
16
|
|
|
'0.1.0', |
|
17
|
|
|
'Boilerplate title', |
|
18
|
|
|
'Boilerplate description', |
|
19
|
|
|
'miscellaneous', |
|
20
|
|
|
'MIT' |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
describe('boilerplate.js', () => { |
|
24
|
|
|
describe('Input and output', () => { |
|
25
|
|
|
it('should answer the questions and create a valid extension', () => { |
|
26
|
|
|
const stream = createStream(['boilerplate']); |
|
27
|
|
|
const next = text => () => stream.write(`${text}\r`) |
|
28
|
|
|
.then(() => stream.once('data')); |
|
29
|
|
|
const stop = (text = '') => () => stream.write(`${text}\r`); |
|
30
|
|
|
|
|
31
|
|
|
const answerAll = () => stream.once('data') |
|
32
|
|
|
.then(next('boilerplate-project')) |
|
33
|
|
|
.then(next('0.1.0')) |
|
34
|
|
|
.then(next('Boilerplate title')) |
|
35
|
|
|
.then(next('Boilerplate description')) |
|
36
|
|
|
.then(next('miscellaneous')) |
|
37
|
|
|
.then(stop('MIT')) |
|
38
|
|
|
.then(() => delay(1000)); |
|
39
|
|
|
|
|
40
|
|
|
return answerAll() |
|
41
|
|
|
.then(() => { |
|
42
|
|
|
const dir = path.join(__dirname, '..', 'boilerplate-project'); |
|
43
|
|
|
expect(dir).to.be.a.directory().with.files([ |
|
44
|
|
|
'README.md', |
|
45
|
|
|
'package.json', |
|
46
|
|
|
'index.js' |
|
47
|
|
|
]); |
|
48
|
|
|
expect(path.join(dir, 'package.json')).to.be.a.file() |
|
49
|
|
|
.with.json.using.schema({ |
|
50
|
|
|
title: 'package.json schema', |
|
51
|
|
|
type: 'object', |
|
52
|
|
|
required: ['name', 'version', 'category', 'license'], |
|
53
|
|
|
properties: { |
|
54
|
|
|
name: { type: 'string' }, |
|
55
|
|
|
version: { type: 'string' } |
|
56
|
|
|
} |
|
57
|
|
|
}); |
|
58
|
|
|
}) |
|
59
|
|
|
.tap(() => rm('boilerplate-project')) |
|
60
|
|
|
.finally(stream.close); |
|
61
|
|
|
}).timeout(20000); |
|
62
|
|
|
}) |
|
63
|
|
|
}); |
|
64
|
|
|
|